package com.briup.ch08;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

//检验ArrayList和LinkedList比较
public class Test3_List {
    public static void main(String[] args) {
        final int NUM = 100000;
        //1.实例化集合对象
        List<String> list = new ArrayList<>();
        //List<String> list = new LinkedList<>();
        //2.开启计时，往集合种放入 100000 个元素
        long start1 = System.currentTimeMillis();
        for (int i = 0; i < NUM; i++) {
            list.add(0,"hello"+i);
        }
        long end1 = System.currentTimeMillis();
        //3.输出时长
        System.out.println(list.getClass().getSimpleName()+"插 入"+NUM+"条数据耗时"+(end1-start1)+"毫秒");
        //4.开启计时，从集合种取 100000 个元素
        long start2 = System.currentTimeMillis();
        for(int i = 0; i < list.size(); i++){
            list.get(i);
        }
        long end2 = System.currentTimeMillis();
        //5.输出时长
        System.out.println(list.getClass().getSimpleName()+"检索"+NUM+"条数据耗时"+(end2-start2)+"毫秒");
    }
}
